package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper  nursingLevelMapper;

    @Override
    public List<NursingLevelVo> selectAll() {
        List<NursingLevelVo> list=nursingLevelMapper.selectAll();
        return list;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        try {
            nursingLevelMapper.add(bean);
        } catch (Exception e) {
            throw new BaseException(BasicEnum. NURSINGLEVEL_INSERT_FAIL);
        }
    }

    @Override
    public PageResponse sel(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevel> p = nursingLevelMapper.sel(name,status);
        return  PageResponse.of(p, NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo updatesel(long id) {
        NursingLevel nursingLevel= nursingLevelMapper.updatesel(id);
        return  BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
    }

    @Override
    public void updata(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updata(bean);
    }

    @Override
    public void del(long id) {

        nursingLevelMapper.del(id);
    }

    @Override
    public void stopstatus(long id, byte status) {
        nursingLevelMapper.stopstatus(id,status);
    }
}
